<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/8
 * Time: 10:12
 */

namespace app\admin\controller;

use app\model\SysSetting as ModelSysSetting;


class SystemManagement extends Member
{
    public function _initialize()
    {
        parent::_initialize();
    }

    /**
     * 系统管理-》平台信息
     * uri:/admin/platform.info
     */
    public function platformInfo(){
        $platform_name = ModelSysSetting::getInstance()->getValue('platform_name');
        $platform_title = ModelSysSetting::getInstance()->getValue('platform_title');
        $platform_logo = ModelSysSetting::getInstance()->getValue('platform_logo');
        $customer_service_hotline = ModelSysSetting::getInstance()->getValue('customer_service_hotline');
        $online_customer_service = ModelSysSetting::getInstance()->getValue('online_customer_service');
        $data=[
            'platformName'=>$platform_name,
            'platformTitle'=>$platform_title,
            'platformLogo'=>$platform_logo,
            'customerServiceHotline'=>$customer_service_hotline,
            'onlineCustomerService'=>$online_customer_service
        ];
        _returnData($data);
    }

    /**
     * 系统管理-》平台信息-》修改
     * uri:/admin/platform.infoModify
     */
    public function platformInfoModify(){
        $platform_name = $this->_getContentParams('platformName');
        $platform_title = $this->_getContentParams('platformTitle');
        $platform_logo = $this->_getContentParams('platformLogo');
        $customer_service_hotline = $this->_getContentParams('customerServiceHotline');
        $online_customer_service = $this->_getContentParams('onlineCustomerService');
        $arr_where=[
            'platform_name'=>$platform_name,
            'platform_title'=>$platform_title,
            'platform_logo'=>$platform_logo,
            'customer_service_hotline'=>$customer_service_hotline,
            'online_customer_service'=>$online_customer_service
        ];
        foreach ($arr_where as $key=>$value){
            $arr=['value'=>$value];
            ModelSysSetting::getInstance()->toUpdate("`key`='$key'",$arr);
        }
        _returnData();
    }

    /**
     * 系统管理-》基础设置
     * uri:/admin/basic.setup
     */
    public function basicSetup(){
//        $type = $this->_getContentParams('type');
//        switch ($type){
//
//        }
        $type= $this->_getContentParams('type');
        $data='';
        switch ($type){
            case 'user':
                $data  = ModelSysSetting::getInstance()->getValue('membership_agreement');
                break;
            case 'courier':
                $data = ModelSysSetting::getInstance()->getValue('courier_agreement');
                break;
            case 'driver':
                $data = ModelSysSetting::getInstance()->getValue('driver_agreement');
                break;
            case 'station':
                $data = ModelSysSetting::getInstance()->getValue('site_agreement');
                break;
            default:
                break;
        }
//        $membership_agreement = ModelSysSetting::getInstance()->getValue('membership_agreement');
//        $courier_agreement = ModelSysSetting::getInstance()->getValue('courier_agreement');
//        $driver_agreement = ModelSysSetting::getInstance()->getValue('driver_agreement');
//        $site_agreement = ModelSysSetting::getInstance()->getValue('site_agreement');
//        $data=[
//            'membershipAgreement'=>$membership_agreement,
//            'courierAgreement'=>$courier_agreement,
//            'driverAgreement'=>$driver_agreement,
//            'siteAgreement'=>$site_agreement
//        ];
        _returnData($data);
    }

    /**
     * 系统管理-》基础设置-》修改
     * uri:/admin/basic.setupModify
     */
    public function basicSetupModify(){
        $type= $this->_getContentParams('type');
        $agreementContent = $this->_getContentParams('agreementContent');
        $arr_where=[
            'value'=>$agreementContent
        ];
        switch ($type){
            case 'user':
                ModelSysSetting::getInstance()->toUpdate("`key`='membership_agreement'",$arr_where);
                break;
            case 'courier':
                ModelSysSetting::getInstance()->toUpdate("`key`='courier_agreement'",$arr_where);
                break;
            case 'driver':
                ModelSysSetting::getInstance()->toUpdate("`key`='driver_agreement'",$arr_where);
                break;
            case 'station':
                ModelSysSetting::getInstance()->toUpdate("`key`='site_agreement'",$arr_where);
                break;
            default:
                break;
        }
//        $membership_agreement = $this->_getContentParams('membershipAgreement');
//        $courier_agreement = $this->_getContentParams('courierAgreement');
//        $driver_agreement = $this->_getContentParams('driverAgreement');
//        $site_agreement = $this->_getContentParams('siteAgreement');
        //ModelSysSetting::getInstance()->toUpdate(['id' => 12], ['value' => $membership_agreement]);

        //exit;
//        $arr_where=[
//            'membership_agreement'=>$membership_agreement,
//            'courier_agreement'=>$courier_agreement,
//            'driver_agreement'=>$driver_agreement,
//            'site_agreement'=>$site_agreement
//        ];
//        foreach ($arr_where as $key=>$value){
//            $arr=['value'=>$value];
//            ModelSysSetting::getInstance()->toUpdate("`key`='$key'",$arr);
//        }
        _returnData();
    }
}